package com.zhaobenquan.batch.listener;

import com.zhaobenquan.domain.Bloginfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.ItemReadListener;

import static java.lang.String.format;

/**
 * @author zhaobenquan
 * @Date 2021/7/2 9:38
 */
public class MyReadListener implements ItemReadListener<Bloginfo> {

    private Logger logger = LoggerFactory.getLogger(MyReadListener.class);



    @Override
    public void beforeRead() {
    }

    @Override
    public void afterRead(Bloginfo bloginfo) {
        logger.info(bloginfo.toString());
    }



    @Override
    public void onReadError(Exception ex) {
        try {
            logger.info(format("%s%n", ex.getMessage()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
